Page({
  data: {
    inputLength: 0,
    maxlength: 200,
    imgList: null,
    rules: [
      {
        name: 'type',
        rule: ['required'],
        msg: ['请选择反馈类型']
      },
      {
        name: 'content',
        rule: ['required'],
        msg: ['请输入反馈内容']
      }
    ],
    uploadUrl: wx.util.interfaceUrl('common.upload.images')['url']
  },
  onLoad: function () {
    
  },
  userInput: function (e) {
    this.setData({
      inputLength: e.detail.value.length
    });
  },
  imgUpload: function (e) {
    if (e.detail.status === 1) {
      this.setData({
        imgList: e.detail.imgArr
      });
    }
  },
  submit: function (e) {
    let formData = e.detail.value;
    let chkRes = wx.form.validation(formData, this.data.rules);
    if (chkRes) {
      wx.util.toast(chkRes);
      return;
    }
    formData.covers = JSON.stringify(this.data.imgList);
    wx.util.request('user.feekback.new', {
      body: formData
    }).then(() => {
      wx.util.toast('已提交');
      setTimeout(() => {
        wx.navigateBack();
      }, 1500);
    });
  }
})